package com.bitao.controller;

import cn.hutool.core.collection.CollectionUtil;
import com.bitao.R;
import com.bitao.TableDataInfo;
import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description: 判断插入数据库结果是否成功
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2025-05-23  10:41
 */
public class BaseController {

    public R<Void> toR(int rows) {
        return rows > 0 ? R.ok() : R.fail();
    }

    public R<Void> toR(boolean result) {
        return result ? R.ok() : R.fail();
    }

    public TableDataInfo getTableDataInfo(List<?> list) {
        if (CollectionUtil.isEmpty(list)) {
            return TableDataInfo.empty();
        }
        return TableDataInfo.success(list, new PageInfo<>(list).getTotal());
    }
}
